<template>
  <el-card class="page-container">
    <template #header>
      <div class="header">
        <h3 class="m-0">基本资料</h3>
      </div>
    </template>

    <el-row>
      <el-col :xs="24" :sm="20" :md="16" :lg="12" :xl="10">
        <el-form
          :model="userInfo"
          :rules="rules"
          ref="formRef"
          label-width="100px"
          size="large"
          class="user-form"
        >
          <el-form-item label="登录名称">
            <el-input v-model="userInfo.username" disabled></el-input>
          </el-form-item>

          <el-form-item label="用户昵称" prop="nickname">
            <el-input
              v-model="userInfo.nickname"
              :disabled="disable"
              placeholder="请输入昵称"
              clearable
            ></el-input>
          </el-form-item>

          <el-form-item label="用户邮箱" prop="email">
            <el-input
              v-model="userInfo.email"
              :disabled="disable"
              placeholder="请输入邮箱"
              clearable
            ></el-input>
          </el-form-item>

          <el-form-item>
            <el-button
              type="success"
              class="bg-[#006400] border-[#006400] w-[100%]"
              @click="updateUserInfo(formRef)"
              >提交修改
            </el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
  </el-card>
</template>

<script lang="ts" setup>
import { reactive, ref } from "vue";

const formRef = ref();
const disable = ref(true);

const userInfo = reactive({
  username: "10000000000",
  nickname: "admin",
  email: "22301000@qq.com",
});

const rules = reactive({
  nickname: [
    { required: true, message: "请输入用户昵称", trigger: "blur" },
    { min: 2, max: 10, message: "长度在 2 到 10 个字符", trigger: "blur" },
  ],
  email: [
    { required: true, message: "请输入邮箱地址", trigger: "blur" },
    { type: "email", message: "请输入正确的邮箱地址", trigger: ["blur", "change"] },
  ],
});

const updateUserInfo = async (formEl: any) => {
  if (!formEl) return;
  disable.value = false;
};
</script>

<style lang="scss" scoped>
.page-container {
  min-height: 100%;
  border-radius: 12px;
}

.header h3 {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-form {
  margin-top: 10px;
}

:deep(.el-button) {
  background-color: #006400 !important;
  border-color: #006400 !important;
  color: white;
  transition: all 0.3s ease;
}

:deep(.el-button:hover) {
  background-color: #004d00 !important;
  border-color: #004d00 !important;
  transform: translateY(-1px);
}
</style>
